/*
		ServEngine framework library
		A library to fast develop JEE online applications
	
		Copyright 2008 José Ignacio de Córdoba Álvaro

		Licensed under the Apache License, Version 2.0 (the "License");
		you may not use this file except in compliance with the License.
		You may obtain a copy of the License at

				http://www.apache.org/licenses/LICENSE-2.0

		Unless required by applicable law or agreed to in writing, software
		distributed under the License is distributed on an "AS IS" BASIS,
		WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
		See the License for the specific language governing permissions and
		limitations under the License.
	
		Jose Ignacio de Cordoba Alvaro
		http://ignacio.decordoba.com
*/

package com.servengine.util;

import java.io.File;

import java.util.Date;

public class FileManagerElement extends File //Comentar que encapsula parte de la lógica de negocio.
{
	private boolean update = true;

	public FileManagerElement(String path, String name)
	{
		super(path, name);
	}

	public FileManagerElement(File path, String name)
	{
		super(path, name);
	}

	/**
	 * @deprecated
	 * @return
	 */
	public long getSize()
	{
		return length();
	}

	public long getLength()
	{
		return length();
	}

	public String getType()
	{
		if (getName().indexOf(".") == -1)
			return "";
		return getName().substring(getName().lastIndexOf(".") + 1).toLowerCase();
	}

	public Date getLastModified()
	{
		return new Date(lastModified());
	}
	/**
	 * @deprecated
	 * @return
	 */
	public Date getDate()
	{
		return new Date(lastModified());
		//return lastModified();
	}

	public void setUpdate(boolean value)
	{
		update = value;
	}

	public boolean isUpdate()
	{
		return update;
	}

	/**
	 * Devuelve si el fichero es de texto. Lo hace comprobando si acaba en .jsp o .css y, si no, lo pide al FileDataSource asociado a este fichero.
	 */
	public boolean isTextfile()
	{
		if (getName().endsWith(".shtml") || getName().endsWith(".jsp") || getName().endsWith(".css"))
			return true;
		return new javax.activation.FileDataSource(this).getContentType().startsWith("text");
	}

	public boolean isBinaryfile()
	{
		return !isTextfile();
	}
}
